//
//  ZDUIUtil.m
//  Yueba
//
//  Created by LL Gan on 12-9-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ZDUIUtil.h"

@implementation ZDUIUtil

+ (void)alertWithMessage:(NSString *)alertBody
{
//    [[[[UIAlertView alloc] initWithTitle:JLocStr(@"Alert") message:alertBody delegate:nil cancelButtonTitle:nil otherButtonTitles:JLocStr(@"OK"), nil] autorelease] show];
}

+(void)autoAdjustLabel:(UILabel *)tmpLabel maxWidth:(CGFloat)width type:(autoAdjustType)_type
{
    CGRect originFrame = tmpLabel.frame;
    CGSize l_size;
    if (tmpLabel.numberOfLines == 1) {
        
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
        CGSize blank_size = [@" " sizeWithFont:tmpLabel.font constrainedToSize:CGSizeMake(width, SCREEN_BOUNDS.size.height)];
        l_size = [tmpLabel.text sizeWithFont:tmpLabel.font constrainedToSize:CGSizeMake(width, blank_size.height*3/2.0f) lineBreakMode:tmpLabel.lineBreakMode];
#else
        NSDictionary *attributes = @{NSFontAttributeName : tmpLabel.font};
        CGSize blank_size = [tmpLabel.text boundingRectWithSize:CGSizeMake(width, SCREEN_BOUNDS.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
        l_size = [tmpLabel.text boundingRectWithSize:CGSizeMake(width, blank_size.height*3/2.0f) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
#endif
    }
    else{
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_8_0
        l_size = [tmpLabel.text sizeWithFont:tmpLabel.font constrainedToSize:CGSizeMake(width, SCREEN_BOUNDS.size.height) lineBreakMode:tmpLabel.lineBreakMode];
#else
        NSDictionary *attributes = @{NSFontAttributeName : tmpLabel.font};
        l_size = [tmpLabel.text boundingRectWithSize:CGSizeMake(width, SCREEN_BOUNDS.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
#endif
    }

    switch (_type) {
        case autoAdjustLeftTop:
        {
            tmpLabel.frame = CGRectMake(originFrame.origin.x, originFrame.origin.y, l_size.width, l_size.height);
        }
            break;
        case autoAdjustRightTop:
        {
            tmpLabel.frame = CGRectMake(originFrame.origin.x-l_size.width, originFrame.origin.y, l_size.width, l_size.height);
        }
            break;
        case autoAdjustCenterTop:
        {
            tmpLabel.frame = CGRectMake((SCREEN_BOUNDS.size.width-l_size.width)/2.0f, originFrame.origin.y, l_size.width, l_size.height);
        }
            break;
        case autoAdjustLeftBottom:
        {
            tmpLabel.frame = CGRectMake(originFrame.origin.x, originFrame.origin.y-l_size.height, l_size.width, l_size.height);
        }
            break;
        case autoAdjustRightBottom:
        {
            tmpLabel.frame = CGRectMake(originFrame.origin.x-l_size.width, originFrame.origin.y-l_size.height, l_size.width, l_size.height);
        }
            break;
        case autoAdjustCenterBottom:
        {
            tmpLabel.frame = CGRectMake((SCREEN_BOUNDS.size.width-l_size.width)/2.0f, originFrame.origin.y-l_size.height, l_size.width, l_size.height);
        }
            break;
        default:
            break;
    }
}

@end
